Skip to main content

Crate omgbase_graph

Crate omgbase_graph 

Source
Expand description

§omgbase-graph

The omgbase graph layer, Rust implementation — the pure half: the semantic nodes a Markdown document’s blocks project (links, wikilinks, tasks, anchors, inline fields) and the authored edge descriptors they and the frontmatter yield (links, frontmatter relations, inline relations), plus URI normalization and relative-path resolution. The contract is spec/graph/README.md in the omgbase repository, with the executable fixtures under spec/graph/cases; SPEC_VERSION is the spec version this crate conforms to. Resolution to node ids, minting, the edge intervals and the doc_edges rollup read and write the database and live in omgbase-store, which calls this crate inside its commit transaction.

use omgbase_format::parse_markdown;
use omgbase_graph::{DstKind, NodeKind, Provenance, extract_doc_edges, node_rows, project_nodes};
use omgbase_properties::DocBlock;

let tree = parse_markdown("# T\n\nSee [x](./x.md#H) and [[note^r1]]\n\nrel:: [[y]]\n");
let ids: Vec<String> = (0..DocBlock::count(&tree.children)).map(|i| format!("b_{i}")).collect();
let blocks = DocBlock::from_blocks(&tree.children, &ids);

let nodes = project_nodes(&blocks);
let kinds: Vec<NodeKind> = nodes.iter().map(|n| n.kind).collect();
assert_eq!(
    kinds,
    [NodeKind::Link, NodeKind::Wikilink, NodeKind::Anchor, NodeKind::Wikilink, NodeKind::InlineField]
);
assert_eq!(nodes[0].span, Some((4, 17)));
let rows = node_rows("d_0", &nodes);
assert!(rows[0].node_id.starts_with("n_") && rows[0].node_id.len() == 14);

let edges = extract_doc_edges(&blocks, None);
assert_eq!(edges.len(), 3);
assert_eq!(edges[0].target, "./x.md");
assert_eq!(edges[0].anchor.as_deref(), Some("H"));
assert_eq!(edges[0].dst_kind, DstKind::Document);
assert_eq!(edges[1].dst_kind, DstKind::Block); // `[[note^r1]]`: a block ref
assert_eq!(edges[2].predicate, "rel"); // and `[[y]]` is not also a plain link
assert_eq!(edges[2].provenance, Provenance::InlineField);

Re-exports§

pub use edges::AnchorKind;
pub use edges::Classified;
pub use edges::DstKind;
pub use edges::EdgeDescriptor;
pub use edges::Provenance;
pub use edges::classify;
pub use edges::extract_block_edges;
pub use edges::extract_doc_edges;
pub use edges::extract_frontmatter_edges;
pub use edges::split_fragment;
pub use mask::mask_code_bytes;
pub use nodes::NodeKind;
pub use nodes::NodeRow;
pub use nodes::ProjectedNode;
pub use nodes::node_id;
pub use nodes::node_rows;
pub use nodes::project_nodes;
pub use path::canonical_path;
pub use path::doc_dir;
pub use path::resolve_relative;
pub use uri::normalize_uri;

Modules§

edges
Edge extraction (§3.1, extraction x2): destination classification, the four block scanners in order with in-block dedup, and the frontmatter relations. Pure: descriptors out; the store resolves them (§3.2).
mask
Code masking with byte-preserving spans (§1).
nodes
Node projection (§2): the Markdown adapter’s nodes over each block’s own, masked text, the md:section shape the store appends, ordinals and node_id.
path
Path resolution (§3.2): a ./ or ../ target against the source document’s directory, and the canonical (no leading /) repo path.
uri
URI normalization (§4) over a WHATWG URL parser (the url crate, as the reference uses Node’s URL).

Constants§

SPEC_VERSION
The spec/graph/VERSION this crate implements (major.minor).